import _ from 'lodash'

const UI = {
  SCREENING: 'SCREENING',
  TOAST: 'TOAST',
  PROJECT_LIST: 'PROJECT_LIST',
  MATERIAL: 'MATERIAL',
  PREVIEW_CAROUSEL: 'PREVIEW_CAROUSEL'
}

const initialState = {
  screening: { // 二级侧边栏
    show: false,
    classificationId: '',
    currentValue: '全部'
  },
  toast: {
    show: false,
    content: '错误提示',
    type: 'error'
  },
  projectList: {
    show: false,
    materialDetail: {}
  },
  material: {
    show: false,
    item: {},
    detail: {}
  },
  previewCarousel: {
    list: [],
    show: false
  },
}

const mutations = {
  [UI.SCREENING] (state, payload) {
    state.screening = {
      ...state.screening,
      ...payload
    }
  },
  [UI.TOAST] (state, payload) {
    state.toast = {
      ...state.toast,
      ...payload
    }
  },
  [UI.PROJECT_LIST] (state, payload) {
    state.projectList = {
      ...state.projectList,
      ...payload
    }
  },
  [UI.MATERIAL] (state, payload) {
    state.material = payload
  },
  [UI.PREVIEW_CAROUSEL] (state, payload) {
    state.previewCarousel = {
      ...state.previewCarousel,
      ...payload
    }
  }
}

const actions = {
  changeScreening ({ commit }, payload) {
    commit(UI.SCREENING, payload)
  },
  changeMessage ({ commit }, payload) {
    commit(UI.TOAST, payload)
  },
  changeProjectModal ({ commit }, payload) {
    commit(UI.PROJECT_LIST, payload)
  },
  changeAddMaterial ({ commit }, payload) {
    commit(UI.MATERIAL, payload)
  },
  changeCarousel ({ commit }, payload) {
    commit(UI.PREVIEW_CAROUSEL, payload)
  }
}

const getters = {}

export default {
  state: _.cloneDeep(initialState),
  mutations,
  actions,
  getters
}
